const apis = require("../apis/request.js");

module.exports = {
    sceneArr: [],
    questisons: null,
    questisonSet: null,
    ttLogin() {
        return new Promise((resolve, reject) => {
            tt.login({
                force: true,
                success(res) {
                    tt.setStorageSync("ttLoginData", res);
                    resolve(res);
                },
                fail() {
                    tt.showModal({
                        title: "温馨提示",
                        content: "请先登录账号才可体验小程序",
                        showCancel: false,
                    });
                },
            });
        })
    },
    // 检测是否广告包
    async checkAdPackage(isFromRoom) {
        const app = getApp()
        if (isFromRoom) {
            // 先判断meat配置  data：1 不看广告  0 看广告
            const { data, meta } = await apis.collectAdStatus()
            tt.setStorageSync("openid_" + app.globalData.appInfo.appId, meta && meta.openId);
            console.log('openid', meta && meta.openId);
            console.log('meta配置：', data === 0 ? "广告包" : '普通包');
            if (data === 0) return true
            if (data === 1) return false
        } else {
            return false
        }
    },
    async enterFromLiveRoom() {
        const { scene = '', query } = tt.getEnterOptionsSync();
        const { live_room_id, clickid } = query
        const sceneArr = await apis.getSceneConfig()
        console.log('live_room_id:', live_room_id, '    是否满足场景值', sceneArr.includes(scene));
        return !!live_room_id || !!clickid || sceneArr.includes(scene);
    },
    // 生成分享配置
    generateShareConfig(path = "/pages/index/index", title = "已累计42223人玩过") {
        return { title, path, }
    },
}